﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

using ActivitySystem.DataContract;

namespace ActivitySystem.DataAccessController
{
    public partial class ActivityDaoController
    {
        public override Activity Select(Guid id)
        {
            var entity = dao.Select(id);
            dao.FillEntity(entity);
            return entity;
        }

        public override void Insert(Activity entity)
        {
            dao.Insert(entity);
            dao.SaveEntity(entity);
        }

        public override void Update(Activity entity)
        {
            dao.Update(entity);
            dao.SaveEntity(entity);
        }

        public int SearchCount(string type, string title, string launcher, DateTime date)
        {
            return dao.SearchCount(type, title, launcher, date);
        }

        public Collection<Activity> Search(string type, string title, string launcher, DateTime date, int pageIndex, int pageSize)
        {
            Collection<Guid> activityIds = dao.Search(type, title, launcher, date, pageIndex, pageSize);
            Collection<Activity> activities = new Collection<Activity>();
            foreach (Guid id in activityIds)
            {
                activities.Add(Select(id));
            }
            return activities;
        }

        protected override void FillEntity(Activity entity) { if (entity != null) { dao.FillEntity(entity); } }
    }
}
